package fun.taostool.controller.taost;

import fun.taostool.common.ResponseData;
import fun.taostool.service.taost.TaostService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @description: File
 * @author: Chensn
 * @time: 2024/10/31
 */
@RestController
@RequestMapping("/taost")
public class TaostController {
    @Resource
    private TaostService taostService;

    /**
     * 备份计划生成
     *
     * @return
     */
    @GetMapping("/plan/generate")
    public ResponseData planGenerate() {
        return ResponseData.success(taostService.bkPlanGenerate());
    }

    /**
     * 开始备份
     *
     * @param tableName 普通表名
     * @return
     */
    @GetMapping("/data/backup")
    public ResponseData dataBackup(@RequestParam(required = false) String tableName) {
        taostService.dataBackup(tableName);
        return ResponseData.success();
    }

    /**
     * 恢复计划生成
     *
     * @return
     */
    @GetMapping("/recovery/plan/generate")
    public ResponseData rePlanGenerate() {
        return ResponseData.success(taostService.rePlanGenerate());
    }

    /**
     * 备份/恢复中断
     *
     * @return
     */
    @GetMapping("/break")
    public ResponseData interruptedProgram() {
        return ResponseData.success(taostService.interruptedProgram(true));
    }

    /**
     * 数据恢复
     *
     * @param tableName 普通表名
     * @return
     */
    @GetMapping("/data/recovery")
    public ResponseData dataRecovery(@RequestParam(required = false) String tableName) {
        return ResponseData.success(taostService.dataRecovery(tableName));
    }


    /**
     * avro文件读取测试
     *
     * @param avroFilePath
     * @return
     */
    @GetMapping("/avro/read")
    public ResponseData avroRead(@RequestParam String avroFilePath) {
        return ResponseData.success(taostService.avroRead(avroFilePath));
    }
}
